import React from 'react'
import { useDispatch } from 'react-redux';
import { loginAction } from './actions'
import { Form, Input, Button, Checkbox } from 'antd';
import { UserOutlined, LockOutlined } from '@ant-design/icons';

const Login = () => {
    const dispatch = useDispatch();
    const login = (val) => {
        console.log(val);
        dispatch(loginAction(val));
        // dispatch(loginAction({ username: 'fdy120', passwd: '1234567' }));
    }
    return (
        <Form
            style={{ width: 300, margin: '50px auto' }}
            name="normal_login"
            className="login-form"
            initialValues={{ remember: true }}
            onFinish={login}
        >
            <Form.Item
                name="username"
                rules={[{ required: true, message: 'Please input your Username!' }]}
            >
                <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="Username" />
            </Form.Item>
            <Form.Item
                name="passwd"
                rules={[{ required: true, message: 'Please input your Password!' }]}
            >
                <Input
                    prefix={<LockOutlined className="site-form-item-icon" />}
                    type="password"
                    placeholder="Password"
                />
            </Form.Item>
            <Form.Item>
                <Form.Item name="remember" valuePropName="checked" noStyle>
                    <Checkbox>Remember me</Checkbox>
                </Form.Item>

                <a className="login-form-forgot" href="">
                    Forgot password
                </a>
            </Form.Item>

            <Form.Item>
                <Button type="primary" htmlType="submit" style={{width:'100%'}}>
                    Log in
                </Button>
                Or <a href="">register now!</a>
            </Form.Item>
        </Form>
    )
}

export default Login
